"use strict";
const SMSClient = require('@alicloud/sms-sdk');
const redis = require("redis");
const client = redis.createClient();
const msMap = require('./sentenceMap');

client.get("index", function (err, reply) {
    let index = reply && reply <= msMap.length ? reply : parseInt(Math.random()* 40);
    const templateParam = {content: ',' + msMap[index]};
    const cofig = {
        accessKeyId: 'LTAIfRcWeJgZ2dy2',
        secretAccessKey: 'AIunlATW7DdIOQzv8C14dVkxbRpcHR'
    };
//初始化sms_client
    let smsClient = new SMSClient(cofig);
//发送短信
    smsClient.sendSMS({
        PhoneNumbers: '17688891552',
        SignName: '静静',
        TemplateCode: 'SMS_133964647',
        TemplateParam: JSON.stringify(templateParam)
    }).then(function (res) {
        let {Code}=res;
        if (Code === 'OK') {
            //处理返回参数
            client.set("index", ++index);
            client.quit();
        }
    }, function (err) {
        client.quit();
        console.log(err)
    });
});

client.on('end', () => {
    console.log(123124)
})
